#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
#include<pthread.h>


/*
	设置子线程为分离属性	
*/

int g_val = 9;

void* mythread(void *arg)
{

	sleep(10);
	int*p = (int*)arg;
	printf("arg=[%d]\n",*p);
	printf("child thread,pid=[%d],id=[%ld]\n",getpid(),pthread_self());
}


int main()
{
	int num = 99;
	pthread_t thread; //返回线程号	
	int ret = pthread_create(&thread,NULL,mythread,&num);
	if(ret != 0)
	{
		printf("thread creat error,[%s]\n",strerror(ret));
		return -1;
	} 

	printf("parent thread,pid=[%d],id=[%ld]\n",getpid(),pthread_self());

	//设置线程为分离属性
	pthread_detach(thread);

	//用pthread_join测试.如果为分离属性，则此函数不阻塞
	int res = pthread_join(thread,NULL);
	if(res!=0)
	{
		printf("pthread_join error:[%s]\n",strerror(res));
	}

	sleep(1);
	return 0;
}
